package day03;

public class Demo06 {
    //移动零
    public static void main(String[] args) {
        //思路：先把非零的个数求出来，后面填补的就全是零了
        int[] nums = {0,1,5,0,3,0,4,6,9,0,4};
        int a = 0;
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        }
        System.out.println();
        System.out.println("移动后的数组遍历为：");
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] != 0){
                nums[a] = nums[i];
                a++;
            }
        }
        for (int i = a; i < nums.length; i++) {
            nums[i] = 0;
        }
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        }
    }
}
